<?php


namespace App\Http\Controllers\Admin;


use App\Http\Controllers\Controller;
use App\Utils\MyLog;
use App\Utils\ResponseUtil;


class RoleSnapshootController  extends Controller
{
    public function paginate(){ //查询ES数据库
        global $gameArea;
        $params = request()->all();
        $params['gameArea'] = $gameArea;
        $result = callRpc('/RoleSnapshootService/paginate',$params,['gameArea'=>$gameArea]);
        // snap_time
        if (isset($result['data']['combat']) && is_array($result['data']['combat'])) {

            foreach ($result['data']['combat'] as &$datum) {
                $datum['base']['uniqueid'] = strval($datum['base']['uniqueid']);
            }
        }
        if (isset($result['data']['bag']) && is_array($result['data']['bag'])) {

            foreach ($result['data']['bag'] as &$datum) {
                $datum['base']['uniqueid'] = '"' . strval($datum['base']['uniqueid']) . '"';
            }
        }
        if (isset($result['data']['stall']) && is_array($result['data']['stall']['sell_item_list'])) {
            foreach ($result['data']['stall']['sell_item_list'] as &$datum) {
                if (isset($datum['base']['uniqueid'])) {
                    $datum['base']['uniqueid'] = '"' . strval($datum['base']['uniqueid']) . '"';
                }
            }
            unset($datum); // 取消引用
        }


        foreach($result['data'] as &$item){
            $item['snap_datetime'] = date("Y-m-d H:i:s",$item['snap_time']);
        }



        return ResponseUtil::json($result);
    }

    public function deleteByDateTime(){
        global $gameArea;
        $dateTime = request()->get('dateTime');
        $result = callRpc('/RoleSnapshootService/deleteByDateTime',['dateTime'=>$dateTime,'gameArea'=>$gameArea],['gameArea'=>$gameArea]);
        return ResponseUtil::success();
    }

    public function rfJsonKey($data){


        return $data;

    }
}
